#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll a[200005];
void solve1() {
    ll ans = 0;
    for (ll i = 0; i < (1LL<<n); i++) {
        ll sum = 0;
        int l1 = -1, l2 = -1;
        for (int j = 0; j < n; j++) {
            if (i & (1LL<<j)) {
                if (l1 != -1 && a[l1] == a[j]) {
                    sum += a[j];
                }
                l1 = j;
            }
            else {
                if (l2 != -1 && a[l2] == a[j]) {
                    sum += a[j];
                }
                l2 = j;
            }
        }
        ans = max(ans, sum);
    }
    printf("%lld\n", ans);
}
int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T;
    scanf("%d", &T);
    // cout << "hello" << endl;
    while (T--) {
        scanf("%d", &n);
        for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
        solve1();
    }
    return 0;
}